import 'package:flutter/material.dart';

class FutureBuilderExample extends StatefulWidget {
  @override
  _FutureBuilderExampleState createState() => _FutureBuilderExampleState();
}

class _FutureBuilderExampleState extends State<FutureBuilderExample> {
  Future<String> getFuture() {
    return Future.delayed(Duration(seconds: 2), () {
      return Future.value('Response');
    });
  }

  @override
  Widget build(BuildContext context) {
    return FutureBuilder<String>(
      builder: (_, AsyncSnapshot<String> snapshot) {
        Widget widget;
        if (snapshot.connectionState == ConnectionState.done) {
          widget = Center(
            child: Text("FutureBuilder Connect Done!+ ${snapshot.data}"),
          );
        } else {
          widget = Center(child: CircularProgressIndicator());
        }

        return Scaffold(
          appBar: AppBar(
            title: Text("FutureBuilderExample"),
          ),
          body: widget,
        );
      },
      future: getFuture(),
    );
  }
}
